CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(myserver C CXX)
set(CMAKE_VERBOSE_MAKEFILE ON)
ENABLE_TESTING()
SET( CMAKE_BUILD_TYPE Debug )

INCLUDE (CheckIncludeFiles)
# usage: CHECK_INCLUDE_FILES (<header> <RESULT_VARIABLE> )

CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)

INCLUDE (CheckFunctionExists)
CHECK_FUNCTION_EXISTS(ioctl HAVE_IOCTL_F)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)


###################COMMON###################
SET(PACKAGE ${PROJECT_NAME})
SET(PKGNAME ${PACKAGE})
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(LOCALEDIR "${PREFIX}/share/locale")

IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS} -fPIC -Wall")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${CFLAGS} -fPIC -Wall")
LINK_DIRECTORIES(
  /usr/local/lib
  /use/lib
)
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
ENDIF()

IF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1 /NODEFAULTLIB:MSVCRT")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG  /NODEFAULTLIB:MSVCRT")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG /NODEFAULTLIB:MSVCRT")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG /NODEFAULTLIB:MSVCRT") 
ENDIF()


IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
	SET(CMAKE_BUILD_TYPE "Release")
ENDIF()

MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS "system name: ${CMAKE_SYSTEM_NAME}")

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/src)



